<?php

namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;
use DateTimeInterface;

class Crm_Agency extends Model implements AuthenticatableContract, AuthorizableContract
{
    use Authenticatable, Authorizable, HasFactory;
    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'crm_agency';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $fillable = [
        'name',
        'shortname',
        'code',
        'idcard',
        'mobile',
        'logo',
        'contacts',
        'address',
        'intro',
        'start_time',
        'end_time',
        'province',
        'province_name',
        'city',
        'city_name',
        'area',
        'area_name',
        'lang',
        'lat'
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function fromDateTime($value)
    {
        return strtotime(parent::fromDateTime($value));
    }

    public function hasManyMechanismImg()
    {
        return $this->hasMany('App\Models\Cms_Mechanism_Img','id','id');
    }
}
